/**
 * 
 */
package com.base.myproject.client.busi.b2c;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.JDBCModelData;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;

/**
 * @author zgw
 *2009-7-24 下午02:05:11
 * javazgw@gmail.com
 */
public class GcodeAttrPanel extends BaseJDBCPanel{
	BaseStore<JDBCModelData> attrgroupstore=null;
	BaseGrid attrgroupgrid = null;
	public GcodeAttrPanel()
	{
		init();
	}
	public void init() {

		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);  
	    centerData.setMargins(new Margins(5, 5, 0, 0));  
	this.add(initWeiget(),centerData);

	}
	public ContentPanel initWeiget() {
		ContentPanel panel = new ContentPanel();
		panel.setFrame(false);
		
		panel.add(CreateGcodeAttr());
		 setMaincomponent(attrgroupgrid);
			registerMainStore(attrgroupstore);
		return panel;
	}

	
	private ContentPanel CreateGcodeAttr()
	{
		ContentPanel panel = new ContentPanel();
		panel.setFrame(false);
//		panel.setSize(400, 400);
		panel.setAutoHeight(true);
		panel.setAutoWidth(true);
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		ColumnConfig attr = new ColumnConfig("attrcode", "属性代码", 100);
		TextField<String> attrtext = new TextField<String>();
		attr.setEditor(new CellEditor(attrtext));
		columns.add(attr);
		ColumnConfig attrname = new ColumnConfig("attrname", "属性代码", 100);
		TextField<String> attrnametext = new TextField<String>();
		attrname.setEditor(new CellEditor(attrnametext));
		columns.add(attrname);
		
		

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");

		type.addField("attrcode");
		type.addField("attrname");

		StoreInfo info = new StoreInfo();

		info.setTablename("b2cgcodeattrgroup");
		info.setKeyname(new String[]{"attrcode"});
		info.setSql("select * from b2cgcodeattrgroup");
//		info.setParent(store);// 关联主表
//		info.setAutoinccolumn("idx"); // 自增字段，如果子表一定需要
//		info.setLinkparentcolumns(new String[] { "ccode" }); // 关联主表字段
		attrgroupstore = new BaseStore<JDBCModelData>(type, info);
//		gudong.setName("gudong");
//		gudong.setKeyname(new String[] { "ccode", "idx" }); // 主键
		ColumnModel cm = new ColumnModel(columns);
		 attrgroupgrid = new BaseGrid(attrgroupstore, cm);

		cbs.setSelectionMode(SelectionMode.SINGLE);

		attrgroupgrid.setSelectionModel(cbs);
		attrgroupgrid.setAutoHeight(true);
		attrgroupgrid.setAutoWidth(true);

		registerStore(attrgroupstore);
		panel.add(attrgroupgrid);
		panel.setScrollMode(Scroll.AUTO);
		return panel;
	}
}
